// pagesCollect/pages/collect/list/list.js
import {
    listMyVillage
} from "../../../api/collect"
import {
    baseUrl
} from "../../../api/request"
import {
    obtainSpecial_List
} from "../../../api/luxian.js";

const app = getApp()

const scroll = {
    page: 1,
    pagesize: 999,
    canLoad: true,
    listEnd: false,
    triggered: false,
}

Page({
    data: {
        scroll: JSON.parse(JSON.stringify(scroll)),
        list: [{
            title: '山水相依，古韵武义',
            image: '../../image/img/image3.png',
            day: 7,
            scenic: 7,
            collect: 7,
            isCollect: true,
            distance: '132.56km',
            village: [{
                name: '范西村',
                image: '../../image/img/蒙版组 3.png'
            }, {
                name: '范西村',
                image: '../../image/img/蒙版组 3.png'
            }, {
                name: '范西村',
                image: '../../image/img/蒙版组 3.png'
            }, {
                name: '范西村',
                image: '../../image/img/蒙版组 3.png'
            }, {
                name: '范西村',
                image: '../../image/img/蒙版组 3.png'
            }, {
                name: '范西村',
                image: '../../image/img/蒙版组 3.png'
            }]
        }, {
            title: '山水相依，古韵武义',
            image: '../../image/img/image3.png',
            day: 7,
            scenic: 7,
            collect: 7,
            isCollect: true,
            distance: '132.56km',
            village: [{
                name: '范西村',
                image: '../../image/img/蒙版组 3.png'
            }, {
                name: '范西村',
                image: '../../image/img/蒙版组 3.png'
            }, {
                name: '范西村',
                image: '../../image/img/蒙版组 3.png'
            }, {
                name: '范西村',
                image: '../../image/img/蒙版组 3.png'
            }, {
                name: '范西村',
                image: '../../image/img/蒙版组 3.png'
            }, {
                name: '范西村',
                image: '../../image/img/蒙版组 3.png'
            }]
        }, {
            title: '山水相依，古韵武义',
            image: '../../image/img/image3.png',
            day: 7,
            scenic: 7,
            collect: 7,
            isCollect: true,
            distance: '132.56km',
            village: [{
                name: '范西村',
                image: '../../image/img/蒙版组 3.png'
            }, {
                name: '范西村',
                image: '../../image/img/蒙版组 3.png'
            }, {
                name: '范西村',
                image: '../../image/img/蒙版组 3.png'
            }, {
                name: '范西村',
                image: '../../image/img/蒙版组 3.png'
            }, {
                name: '范西村',
                image: '../../image/img/蒙版组 3.png'
            }, {
                name: '范西村',
                image: '../../image/img/蒙版组 3.png'
            }]
        }],
        navData: {
            title: '推荐列表',
            level: 2
        },
        navHeight: 32,
        navTop: 48,
    },
    onLoad(e) {
        this.setData({
            ['navData.title']: e.name || '推荐列表',
            navHeight: app.globalData.navHeight, //导航栏高度
            navTop: app.globalData.navTop, //导航栏距顶部距离
        });
        // this.refresh()
        this.allNameTopics(e.topicId)
        // console.log(e);
    },
    getlist() {
        return false;
        if (!this.data.scroll.canLoad) {
            return false;
        }
        let {
            scroll,
            list
        } = this.data;
        scroll.canLoad = false;
        listMyVillage({
            pageNum: scroll.page,
            pageSize: scroll.pagesize
        }).then(res => {
            scroll.triggered = false;
            let newlist = res.data.rows;
            scroll.canLoad = true;

            newlist.forEach(item => {
                if (item.villageImage) {
                    item.image = baseUrl + item.villageImage.split(',')[0];
                }
            })

            list = [
                ...list,
                ...newlist
            ]
            if (newlist.length < scroll.pagesize) {
                this.setData({
                    ['scroll.listEnd']: true
                })
            } else {
                scroll.page++
            }
            this.setData({
                list
            })
        }, function (err) {
            scroll.triggered = false;
            scroll.canLoad = true;
            this.setData({
                list
            })
        })
    },
    refresh() {
        this.setData({
            scroll: JSON.parse(JSON.stringify(scroll)),
            list: []
        })
        this.getlist()
    },
    getMore() {
        // console.log(e)
        if (this.data.scroll.canLoad && !this.data.scroll.listEnd) {
            this.getlist()
        }
    },

    // 获取某一专题信息
    async allNameTopics(topicId) {
        console.log(topicId);
        let result = await obtainSpecial_List({topicId})
        this.setData({
            list: result.data.rows
        })
        console.log('result',result.data.rows);
    }
})